<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.Calendar"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
//FX获取文件路径方法
function readFileFirefox(fileBrowser) {
    try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    } 
    catch (e) {
        alert('无法访问本地文件，由于浏览器安全设置。为了克服这一点，请按照下列步骤操作：(1)在地址栏输入"about:config";(2) 右键点击并选择 New->Boolean; (3) 输入"signed.applets.codebase_principal_support" （不含引号）作为一个新的首选项的名称;(4) 点击OK并试着重新加载文件');
        return;
    }
    var fileName=fileBrowser.value; //这一步就能得到客户端完整路径。下面的是否判断的太复杂，还有下面得到ie的也很复杂。
    var file = Components.classes["@mozilla.org/file/local;1"]
        .createInstance(Components.interfaces.nsILocalFile);
    try {
        // Back slashes for windows
        file.initWithPath( fileName.replace(/\//g, "\\\\") );
    }
    catch(e) {
        if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;
        alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");
        return;
    }
    if ( file.exists() == false ) {
        alert("File '" + fileName + "' not found.");
        return;
    }


  return file.path;
}


//根据不同浏览器获取路径
function getvl(obj){
//判断浏览器
  var Sys = {}; 
  var ua = navigator.userAgent.toLowerCase(); 
  var s; 
  (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 
  (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : 
  (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : 
  (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : 
  (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
  var file_url="";
  if(Sys.ie<="6.0"){
    //ie5.5,ie6.0
    file_url = obj.value;
  }else if(Sys.ie>="7.0"){
    //ie7,ie8
    obj.select();
    file_url = document.selection.createRange().text;
  }else if(Sys.firefox){
    //fx
    //file_url = document.getElementById("file").files[0].getAsDataURL();//获取的路径为FF识别的加密字符串
    file_url = readFileFirefox(obj);
  }else if(Sys.chrome){
    file_url = obj.value;
  }
  alert(file_url);
  document.getElementById("filePath").value=file_url;
} 
	function checkForm(){
		var a =  document.getElementById("file").value;
		if(!a){
			document.getElementById('message').innerHTML="请选择文件！";
			return false;
		}else{
			document.getElementById('message').innerHTML="";
			return true;
		}
	}
	
</script>
<title>财务数据导入</title>
</head>
<body>
<form action="dataImport.do?method=importData" method="post"
	onsubmit="return checkForm();" enctype="multipart/form-data">
<center>
<h3>财务数据导入</h3>
<table cellpadding="0" cellspacing="0" width="50%">
	<tr>
		<td rowspan="3" width="70%">
		<table border="1px" cellpadding="0" cellspacing="0" width="100%"
			bordercolor="#cecece">
			<tr>
				<td align="center">请选择时间：</td>
				<td align="center">
				<table border="0px" cellpadding="2" cellspacing="0">
					<tr>
						<td><select style="width: 60px" id="year" name="year">
							<%
								int thisYear = Calendar.getInstance().get(Calendar.YEAR);
								for (int i = thisYear - 10; i <= thisYear; i++) {
							%>
							<%
								if (i == thisYear) {
							%><option selected="selected" value="<%=i%>"><%=i%></option>
							<%
								} else {
							%><option value="<%=i%>"><%=i%></option>
							<%
								}
								}
							%>
						</select></td>
						<td>年</td>
						<td><select style="width: 40px" id="month" name="month">
							<%
								int thisMonth = Calendar.getInstance().get(Calendar.MONTH) + 1;
								for (int i = 1; i <= 12; i++) {
							%>
							<%
								if (i == thisMonth) {
							%><option selected="selected" value="<%=i%>"><%=i%></option>
							<%
								} else {
							%>
							<option value="<%=i%>"><%=i%></option>
							<%
								}
								}
							%>
						</select></td>
						<td>月</td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td align="center">请选择类型：</td>
				<td align="center"><select style="width: 150px;"
					id="salaryItemType" name="salaryItemType">
					<c:if test="${!empty types}">
						<c:forEach items="${types}" var="type">
							<option value="${type.id }">${type.name }</option>
						</c:forEach>
					</c:if>
					<option>工资明细表</option>
				</select></td>
			</tr>
			<tr>
				<td align="center">请选择文件：</td>
				<td align="center"><input type="file" id="file" name="file"
					accept=".xls,.xlsx"></td>
			</tr>
		</table>
		</td>
		<td height="30dp"><span id="message3" style="color: red;"></span>
		</td>
	</tr>
	<tr>
		<td height="30dp"><span id="message2" style="color: red;"></span></td>
	</tr>
	<tr>
		<td height="30dp"><span id="message" style="color: red;"></span></td>
	</tr>
</table>

<input style="margin-left: 200px; margin-top: 10px;" type="submit"
	value="上传" width="80px"></center>
</form>
</body>
</html>